//: [Previous](@previous)

import Foundation

/*:
 斐波那契数
 0 1 1 2 3 5 8 13 21 34...
 */

func fib1(_ n: Int) -> Int {
    if n <= 1 {
        return n
    }
    return fib1(n-1) + fib1(n-2)
}

func fib2(_ n: Int) -> Int {
    if n <= 1 {
        return n
    }

    var first = 0
    var second = 1
    for _ in 1..<n {
        (first, second) = (second, first + second)
    }
    return second
}

test(title: "fib1") {
    print(fib1(4))
}

test(title: "fib2") {
    print(fib2(4))
}


//: [Next](@next)
